import data
from Numeric import ones
from Numeric import zeros
from numpy.core.numeric import inf

from pymc import *

__author__="kamillo"
__date__ ="$2009-11-02 00:31:38$"

import random

def rects():
    data = []
    while len(data) < 10000 :
        cand1 = random.uniform(-1,1)
        cand2 = random.uniform(-1,1)
        if (cand1 < -0.5 or cand1 > 0.5) and (cand2 < -0.5 or cand2 > 0.5):
            data.append([cand1,cand2])
    print data
    return data

def ellipse():
    X = Uniform('X', zeros(2)-1, ones(2))
    X.value = [0.5,0.5]
    @potential
    def s2(X=X):
        if sum((X)**2) >= 1.0:
            return -inf
        else:
            return 0.0
    mc = MCMC([X, s2])
    mc.sample(50000)
    #plot(X.trace()[:,0], X.trace()[:,1],',')
    
    return X.trace()


def rect():

    X = Uniform('X', zeros(2)-1, ones(2))
    mc = MCMC([X])
    mc.sample(20000)
    return X.trace()
    data = []
    for i in range(10000):
        data.append([random.uniform(-1,1),random.uniform(-1,1)])
    #return data

def donutdel():
    data = []
    file = open('uniform_ellipse50k.txt','r')
    file2 = open('donut25k.txt','w')
    r = 0.5
    lines = file.readlines()
    for line in lines:
            floated = []
            splitted = line.split(" ")
            #input.append(line.split(" "))
            for s in splitted:
                s = float(s)
                floated.append(s)
            data.append(floated)
    for i in data:
        
        if i[0]**2+i[1]**2 > r**2:
            file2.write(str(i[0])+" ")
            file2.write(str(i[1])+"\n")

def wholerec():
        data = []
        for i in range (20000):
            data.append([random.randint(0,650),random.randint(0,650)])
        return data

def ellipsedel():
    data = []
    file = open('uniform_ellipse50k.txt','r')
    file2 = open('donut25k.txt','w')
    r = 0.5
    lines = file.readlines()
    for line in lines:
            floated = []
            splitted = line.split(" ")
            #input.append(line.split(" "))
            for s in splitted:
                s = float(s)
                floated.append(s)
            data.append(floated)
    for i in data:

        if i[0]**2+i[1]**2 > r**2:
            file2.write(str(i[0])+" ")
            file2.write(str(i[1])+"\n")
if __name__ == "__main__":

    #donutdel()
    data =[]
    file2 = open('n_donut.txt','w')
    file = open('donut.txt','r')
    lines = file.readlines()
    for line in lines:
            floated = []
            splitted = line.split(" ")
            #input.append(line.split(" "))
            for s in splitted:
                s = float(s)
                floated.append(s)
            data.append(floated)
    for i in data:
        
        file2.write(str(int((i[0]*300)+325))+" ")
        file2.write(str(int((i[1]*300)+325))+"\n")
    file.close()